package com.dc.refactoring._4_简化条件表达式._3_ConsolidateDuplicateConditionalFragments;

/**
 * Description: 合并重复的条件片段
 * @author: gdc
 * @date: 2020/12/6
 * @version 1.0
 */
public class Demo {

    int PRICE = 100;
    int ROLE = 1;

    /**
     * 改造前，条件分支中，存在重复的代码
     */
    public void fun1(){
        double total;
        if (isSpecialDeal()){
            total = PRICE * 0.95;
            send();
        }else {
            total = PRICE * 0.98;
            send();
        }
    }

    /**
     * 改造后，将重复的代码移出条件外
     */
    public void fun2(){
        double total;
        if (isSpecialDeal()){
            total = PRICE * 0.95;
        }else {
            total = PRICE * 0.98;
        }
        send();
    }

    private void send(){}

    private boolean isSpecialDeal(){
        return ROLE ==1;
    }
}
